/**
 * 
 */
package com.padbot.qm.web;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.padbot.qm.security.UserSessionContainer;
import com.padbot.qm.util.Constants;

/**
 * @author Deng
 *
 */
public class ContextServletListener implements ServletContextListener {
	
	private static Logger logger = LoggerFactory.getLogger(ContextServletListener.class);

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		logger.debug("Load the properties file");
		Properties props = new Properties(); 
        InputStream inputStream = null; 
        try { 
            inputStream = getClass().getResourceAsStream("/config.properties"); 
            props.load(inputStream);
            logger.debug("properties: "+props);
            Constants.init(props);
        } catch (IOException ex) { 
        	logger.error("Faild load the properties file", ex);
        } finally {
        	if(null != inputStream){
        		try {
					inputStream.close();
				} catch (IOException e) {
					logger.error("Faild close the streeam");
				}
        	}
        }
		logger.debug("Completed load the properties file");
		UserSessionContainer.getInstance().startWatch();
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
	}

}
